//
//  YTBaseButton.m
//  JiliMobile
//
//  Created by chinatsp on 16/8/8.
//  Copyright © 2016年 YuanTe. All rights reserved.
//

#import "YTBaseButton.h"
#define kRatio 0.3
@implementation YTBaseButton

- (void)awakeFromNib
{   [super awakeFromNib];
    [self setupContenMode];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self setupContenMode];
    }
    return self;
}

- (void)setupContenMode
{
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.numberOfLines = 0;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    //设置imageView的位置
//    CGFloat imageX = 0;
//    CGFloat imageY = 0;
//    CGFloat imageW = self.bounds.size.width;
    CGFloat imageH = self.bounds.size.height *kRatio;
    CGFloat imageW = imageH;
    
    CGFloat imageX = (self.bounds.size.width-imageW)/2;
    CGFloat imageY = 15;
    self.imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
   // self.imageView.layer.cornerRadius = imageW*0.5;
    self.imageView.clipsToBounds = YES;
    
    //设置label的位置
    CGFloat lableX = 0;
    CGFloat lableY = self.bounds.size.height *kRatio +5;
    CGFloat lableW = self.bounds.size.width;
    CGFloat lableH = self.bounds.size.height *(1-kRatio);
    self.titleLabel.frame = CGRectMake(lableX, lableY, lableW, lableH);
}

@end
